package com.secsbrain.cmdb.web.controller;

import java.util.Date;
import java.util.List;

import com.secsbrain.sso.core.SsoHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.plugins.Page;
import com.secsbrain.cmdb.biz.IRedisService;
import com.secsbrain.common.ResponseResult;
import com.secsbrain.cmdb.dal.model.Redis;

/**
 * 数据库端口控制层
 * @author zhaoyi
 *
 */
@RestController
@RequestMapping("api/redis")
public class RedisController{
	
    @Autowired
    IRedisService redisService;
    
    /**
     * 功能描述: <br>
     * 查询列表
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResponseResult<?> queryList(Integer page, Integer limit,Redis params) {
    	Page<Redis> pageBean=new Page<Redis>(page, limit);
    	Page<Redis> result=redisService.selectPage(pageBean, params);
    	return new ResponseResult(result);
    }
    
    /**
     * 功能描述: <br>
     * 查询所有列表
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "/allList", method = RequestMethod.GET)
    public ResponseResult<?> queryAllList(Redis params) {
    	List<Redis> list=redisService.selectList(params);
    	return new ResponseResult(list);
    }
    
    /**
     * 功能描述: <br>
     * 新增
     *
     * @param redis
     * @return
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public ResponseResult<?> insert(@RequestBody Redis redis) {
    	redis.setCreateTime(new Date());
    	redis.setCreator(SsoHelper.currentUser().getNickname());
    	redisService.insertSelective(redis);
    	return new ResponseResult();
    }
    
    /**
     * 功能描述: <br>
     * 更新
     *
     * @param redis
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    public ResponseResult<?> update(@RequestBody Redis redis) {
    	redis.setUpdateTime(new Date());
    	redis.setUpdator(SsoHelper.currentUser().getNickname());
    	redisService.updateSelectiveById(redis);
    	return new ResponseResult();
    }
    
    /**
     * 功能描述: <br>
     * 删除
     *
     * @param redis
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    public ResponseResult<?> delete(@RequestBody Redis redis) {
    	redisService.deleteById(redis.getId());
    	return new ResponseResult();
    }
    
}
